Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR introduces the HasItemThat method for collections, enabling developers to apply expectations on individual items within collections. The feature provides a more flexible alternative to existing HasItem methods by allowing full expectation chains on collection items.
- Adds
HasItemThatmethods forIEnumerable<T>,IAsyncEnumerable<T>, andImmutableArray<T> - Implements comprehensive test coverage across regular, immutable, and async enumerable collections
- Fixes a bug in AndNode/OrNode filtering to prevent circular references during expectation building
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
ThatEnumerable.HasItemThat.cs |
Core implementation of HasItemThat for sync enumerables and immutable arrays |
ThatAsyncEnumerable.HasItemThat.cs |
Implementation for async enumerables with proper cancellation handling |
ThatEnumerable.HasItemThat.Tests.cs |
Comprehensive test suite covering various scenarios including null handling and error messages |
ThatEnumerable.HasItemThat.ImmutableTests.cs |
Tests specific to ImmutableArray collections |
ThatAsyncEnumerable.HasItemThat.Tests.cs |
Tests for async enumerable functionality |
AndNode.cs / OrNode.cs |
Bug fix to prevent infinite loops in expectation building |
| API test files | Updates to expected API surface for new methods |
| Documentation | Updates with usage examples for the new feature |
Comments suppressed due to low confidence (8)
Tests/aweXpect.Tests/Collections/ThatEnumerable.HasItemThat.Tests.cs:67
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsNoItemAtGivenIndex_ShouldSucceed()
Tests/aweXpect.Tests/Collections/ThatEnumerable.HasItemThat.ImmutableTests.cs:15
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsDifferentItemAtGivenIndex_ShouldSucceed()
Tests/aweXpect.Tests/Collections/ThatEnumerable.HasItemThat.ImmutableTests.cs:45
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsNoItemAtGivenIndex_ShouldSucceed()
Tests/aweXpect.Tests/Collections/ThatEnumerable.HasItemThat.Tests.cs:37
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsDifferentItemAtGivenIndex_ShouldSucceed()
Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.HasItemThat.Tests.cs:26
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsDifferentItemAtGivenIndex_ShouldSucceed()
Tests/aweXpect.Tests/Collections/ThatAsyncEnumerable.HasItemThat.Tests.cs:56
- The test method name is misleading. It says 'ShouldSucceed' but the test expects the assertion to fail and throw an XunitException.
public async Task WhenEnumerableContainsNoItemAtGivenIndex_ShouldSucceed()
You can now also use expectations on the individual items.
```csharp
IEnumerable<string> values = ["0th item", "1st item", "2nd item", "3rd item"];
await Expect.That(values).HasItemThat(it => it.IsEqualTo("1st item")).AtIndex(1);
await Expect.That(values).HasItemThat(it => it.StartsWith("2nd").And.EndsWith("item")).AtAnyIndex();
```
*Note: The same expectation works also for `IAsyncEnumerable<T>`.*
fe24491 to
baf484f
Compare
dde49ab to
d141588
Compare
|
Test Results 4 files ±0 4 suites ±0 20s ⏱️ -2s Results for commit d141588. ± Comparison against base commit b774dc8. This pull request removes 54 and adds 54 tests. Note that renamed tests count towards both. |
|
This is addressed in release v2.20.0. |



You can now also use expectations on the individual items.
Note: The same expectation works also for
IAsyncEnumerable<T>.